package service

import (
	"app/internal/store/conf"
	"app/internal/store/dao"
	"app/util"
	"sync"
)

var srvlock sync.Once
var srv *Service

var (
	daoErrorString = "dao is nil"
)

type Service struct {
	dao *dao.Dao
	cf  *conf.AppConf
}

func NewService(conf *conf.AppConf) (s *Service) {

	s = &Service{
		dao: dao.New(conf),
		cf:  conf,
	}
	return s
}

func InitService(conf *conf.AppConf) {
	srvlock.Do(func() {
		srv = NewService(conf)
	})
}
func GetServiceInstance() *Service {
	return srv
}

func (s *Service) Close() {
	s.dao.Close()
	util.Error("Service Close")
}
